﻿#define _CRT_SECURE_NO_WARNINGS
#include"Tree.h"



//先创建树节点
BTNode* buyNode(BtDatatype x)
{
	BTNode* node = (BTNode*)malloc(sizeof(BTNode));
	node->data = x;
	node->left = NULL;
	node->right = NULL;
	return node;
}

//手动构建一颗树
BTNode* CreatTree()
{
	BTNode* nodeA = buyNode('A');
	BTNode* nodeB = buyNode('B');
	BTNode* nodeC = buyNode('C');
	BTNode* nodeD = buyNode('D');
	BTNode* nodeE = buyNode('E');
	BTNode* nodeF = buyNode('F');

	nodeA->left = nodeB;
	nodeA->right = nodeC;
	nodeB->left = nodeD;
	nodeC->left = nodeE;
	nodeC->right = nodeF;

	return nodeA;
}

void test1()
{
	BTNode* root = CreatTree();
	//链式树不存在插入数据和删除数据，基本操作是遍历查找，用递归的形式
	//PreOrder(root);
	//InOrder(root);
	//PostOrder(root);

	printf("Node:%d\n", BinaryTreeSize(root));
	printf("Node:%d\n", BinaryTreeSize(root));
	printf("LeaveNode:%d\n", BinaryTreeLeafSize(root));
	printf("kNode:%d\n", BinaryTreeLevelKSize(root, 2));
	printf("kNode:%d\n", BinaryTreeLevelKSize(root, 1));
	printf("kNode:%d\n", BinaryTreeLevelKSize(root, 3));
	printf("DeepNode:%d\n", BinaryTreeDepth(root));
	BTNode* find = BinaryTreeFind(root, 'S');
	if (find == NULL)
	{
		printf("not find\n");
	}
	else
	{
		printf("have found\n");
	}

	//判断⼆叉树是否是完全⼆叉树
	if (BinaryTreeComplete(root))
	{
		printf("是完全二叉树\n");
	}
	else
	{
		printf("不是完全二叉树\n");

	}

	//销毁树
	BinaryTreeDestory(&root);

}

int main()
{
	test1();
	return 0;
}